package Terminal.View;

import java.awt.Font;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;

import Terminal.View.Gestori.GestoreAutenticazione;
import Terminal.View.Gestori.GestoreInterfaccia;


public class JPannelloAutenticazione extends JPanel {//extends JPannelloMain{

	private static final long serialVersionUID = 1L;
		
	private JLabel usernameLabel;
	private JLabel passwordLabel;
	
	private JTextField usernameField;
	private JPasswordField passwordField;
	private JButton submit;
	
	private GestoreAutenticazione mediator = GestoreAutenticazione.istanza();
		
	public JPannelloAutenticazione() {
	
		super();
		this.createComponents();
	}
	public void createComponents() {
		
		this.setLayout(null);
		this.setBounds(0, 151, 1366, 617);
		
		this.setLabels();
		this.setFields();	
	    this.setSubmit();
	    
	    this.add(usernameLabel);
	    this.add(passwordLabel);
	    this.add(usernameField);
	    this.add(passwordField);
	    this.add(submit);
		
	    this.setVisible(true);
	}

	
	private void setLabels()
	{
		usernameLabel = new JLabel();
		passwordLabel = new JLabel();		
		
		usernameLabel.setText("Username");
		passwordLabel.setText("Password");
		
		usernameLabel.setBounds(250, 100, 300, 100);
		passwordLabel.setBounds(250, 200, 300, 100);
		
		usernameLabel.setFont(new Font(usernameLabel.getFont().getName(), Font.PLAIN,40));
	    passwordLabel.setFont(new Font(passwordLabel.getFont().getName(), Font.PLAIN,40));	
	}
	
	private void setFields()
	{
		usernameField = new JTextField("faudan");
		passwordField = new JPasswordField("asdfghjkl");		
		
		usernameField.setBounds(550, 125, 500, 50);
		passwordField.setBounds(550, 225, 500, 50);
		
		usernameField.setMargin(new Insets(0, 10, 0, 0));
		passwordField.setMargin(new Insets(0, 10, 0, 0));		
		    
	    
	    usernameField.setFont(new Font(usernameField.getFont().getName(), usernameField.getFont().getStyle(),24));
	    passwordField.setFont(new Font(passwordField.getFont().getName(), passwordField.getFont().getStyle(),24));			
	}
	
	private void setSubmit()
	{
		submit = new JButton();				
		submit.setText("Login");			
		submit.setBounds(950, 325, 100, 50);
	 		
	    submit.setFont(new Font(submit.getFont().getName(), Font.PLAIN,24));
	    
	    submit.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent arg0) {
				
				mediator.smista("Autenticarsi", "Autentica");
				
			}
		});
	}
	
	public String getUsername()
	{
		return usernameField.getText();
	}
	
	public String getPassword()
	{
		return String.valueOf( passwordField.getPassword() );
	}
	
}